package com.link2room.soundwave.controller.inside;


import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.soundwave.dto.param.inside.*;
import com.link2room.soundwave.dto.result.base.PmsMemberInfoDto;
import com.link2room.soundwave.util.HandlerUtil;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * Created by VegetaKo on 2016/9/18.
 */
@Api(tags = "PMS会员")
@RestController
@RequestMapping("/in/PMSMembers")
public class PMSMemberInsideController {


    @RequestMapping(value = "/CheckRegister", method = RequestMethod.GET)
    public BaseResultDto checkRegister(
            @RequestParam(value = "lhotelCode", required = false) String lhotelCode,
            @RequestParam(value = "mobile", required = false) String mobile,
            @RequestParam(value = "memberName", required = false) String memberName
    ) throws Exception {
        MemberLoginInsideParamDto memberLoginInsideParamDto = new MemberLoginInsideParamDto();
        memberLoginInsideParamDto.setMobile(mobile);
        memberLoginInsideParamDto.setMemberName(memberName);
        HandlerUtil.pmsMemberHandler().checkRegisterHandler(memberLoginInsideParamDto);
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultCode(0);
        return l2rRs;
    }

    @RequestMapping(value = "/NewPMSMember", method = RequestMethod.POST)
    public BaseResultDto<PmsMemberInfoDto> newPMSMember(
            @RequestBody MemberLoginInsideParamDto memberLoginInsideParamDto
    ) throws Exception {
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(HandlerUtil.pmsMemberHandler().newPMSMemberHandler(memberLoginInsideParamDto));
        return l2rRs;
    }

    @RequestMapping(value = "/CheckPMSMember", method = RequestMethod.GET)
    public BaseResultDto<PmsMemberInfoDto> checkPMSMember(
            @RequestParam(value = "lhotelCode", required = false) String lhotelCode,
            @RequestParam(value = "l2RMemberNo", required = false) String l2RMemberNo
    ) throws Exception {
        BaseResultDto l2rRs = new BaseResultDto();
        MemberLoginInsideParamDto memberLoginParamDto = new MemberLoginInsideParamDto();
        memberLoginParamDto.setLhotelCode(lhotelCode);
        memberLoginParamDto.setL2RMemberNo(l2RMemberNo);
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(HandlerUtil.pmsMemberHandler().checkPMSMemberHandler(memberLoginParamDto));
        return l2rRs;
    }

    @RequestMapping(value = "/BindingPMSMember", method = RequestMethod.GET)
    public BaseResultDto bindingPMSMember(
            @RequestParam(value = "lhotelCode", required = false) String lhotelCode,
            @RequestParam(value = "loginId", required = false) String loginId,
            @RequestParam(value = "loginPasswd", required = false) String loginPasswd,
            @RequestParam(value = "l2RMemberNo", required = false) String l2RMemberNo
    ) throws Exception {
        BaseResultDto l2rRs = new BaseResultDto();
        MemberLoginInsideParamDto memberLoginParamDto = new MemberLoginInsideParamDto();
        memberLoginParamDto.setLhotelCode(lhotelCode);
        memberLoginParamDto.setLoginId(loginId);
        memberLoginParamDto.setLoginPasswd(loginPasswd);
        memberLoginParamDto.setL2RMemberNo(l2RMemberNo);
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(HandlerUtil.pmsMemberHandler().bindingPMSMemberHandler(memberLoginParamDto));
        return l2rRs;
    }

    @RequestMapping(value = "/UnbindingPMSMember", method = RequestMethod.POST)
    public BaseResultDto unbindingPMSMember(
            @RequestBody MemberLoginInsideParamDto memberLoginParamDto
    ) throws Exception {
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultCode(0);
        HandlerUtil.pmsMemberHandler().unbindingPMSMemberHandler(memberLoginParamDto);
        return l2rRs;
    }

    @RequestMapping(value = "/UsableCoupons", method = RequestMethod.GET)
    public BaseResultDto getUsableCoupons(
            @RequestParam(value = "lhotelCode", required = false) String lhotelCode,
            @RequestParam(value = "arr", required = false) String arr,
            @RequestParam(value = "rmtype", required = false) String rmtype,
            @RequestParam(value = "rateCode", required = false) String rateCode,
            @RequestParam(value = "amount", required = false) BigDecimal amount,
            @RequestParam(value = "l2RMemberNo", required = false) String l2RMemberNo
    ) throws Exception {
        UsableCouopnsInsideParamDto usableCouopnsInsideParamDto = new UsableCouopnsInsideParamDto();
        BaseResultDto l2rRs = new BaseResultDto();
        usableCouopnsInsideParamDto.setLhotelCode(lhotelCode);
        usableCouopnsInsideParamDto.setArr(arr);
        usableCouopnsInsideParamDto.setRmtype(rmtype);
        usableCouopnsInsideParamDto.setRateCode(rateCode);
        usableCouopnsInsideParamDto.setL2RMemberNo(l2RMemberNo);
        usableCouopnsInsideParamDto.setAmount(amount);
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(HandlerUtil.pmsMemberHandler().getUsableCouponsHandler(usableCouopnsInsideParamDto));
        return l2rRs;
    }

    @RequestMapping(value = "/AutoMember", method = RequestMethod.POST)
    public BaseResultDto matchLogin(
            @RequestBody MemberLoginInsideParamDto memberLoginInsideParamDto
    ) throws Exception {

        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(HandlerUtil.pmsMemberHandler().autoMemberHandler(memberLoginInsideParamDto));
        return l2rRs;
    }

    @RequestMapping(value = "/SyncMember", method = RequestMethod.GET)
    public BaseResultDto syncMember(
            @RequestParam(value = "l2RMemberNo", required = false) String l2RMemberNo,
            @RequestParam(value = "memberName", required = false) String memberName,
            @RequestParam(value = "mobile", required = false) String mobile
    ) throws Exception {
        MemberLoginInsideParamDto memberLoginInsideParamDto =new MemberLoginInsideParamDto();
        memberLoginInsideParamDto.setL2RMemberNo(l2RMemberNo);
        memberLoginInsideParamDto.setMobile(mobile);
        memberLoginInsideParamDto.setMemberName(memberName);
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(HandlerUtil.pmsMemberHandler().syncMemberHandler(memberLoginInsideParamDto));
        return l2rRs;
    }



    @RequestMapping(value = "/Points", method = RequestMethod.GET)
    public BaseResultDto getPMSMemberPoints(
            @RequestParam(value = "lhotelCode", required = false) String lhotelCode,
            @RequestParam(value = "l2RMemberNo", required = false) String l2RMemberNo
    ) throws Exception {
        BaseResultDto l2rRs = new BaseResultDto();
        MemberLoginInsideParamDto memberLoginParamDto = new MemberLoginInsideParamDto();
        memberLoginParamDto.setLhotelCode(lhotelCode);
        memberLoginParamDto.setL2RMemberNo(l2RMemberNo);
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(HandlerUtil.pmsMemberHandler().getPmsMemberPointsHandler(memberLoginParamDto));
        return l2rRs;
    }

    @RequestMapping(value = "/PointsDetail", method = RequestMethod.GET)
    public BaseResultDto getPMSMemberPointsDetail(
            @RequestParam(value = "lhotelCode", required = false) String lhotelCode,
            @RequestParam(value = "l2RMemberNo", required = false) String l2RMemberNo
    ) throws Exception {
        BaseResultDto l2rRs = new BaseResultDto();
        MemberLoginInsideParamDto memberLoginParamDto = new MemberLoginInsideParamDto();
        memberLoginParamDto.setLhotelCode(lhotelCode);
        memberLoginParamDto.setL2RMemberNo(l2RMemberNo);
        l2rRs.setResultCode(0);
        l2rRs.setListToQueryResult(HandlerUtil.pmsMemberHandler().getPmsMemberPointsDetailHandler(memberLoginParamDto));
        return l2rRs;
    }


    @RequestMapping(value = "/Coupons", method = RequestMethod.GET)
    public BaseResultDto getPMSMemberCoupons(
            @RequestParam(value = "lhotelCode", required = false) String lhotelCode,
            @RequestParam(value = "l2RMemberNo", required = false) String l2RMemberNo,
            @RequestParam(value="pageSize",required = false)Integer pageSize,
            @RequestParam(value="currentPage",required = false)Integer currentPage
    ) throws Exception {
        BaseResultDto l2rRs = new BaseResultDto();
        MemberLoginInsideParamDto memberLoginParamDto = new MemberLoginInsideParamDto();
        memberLoginParamDto.setLhotelCode(lhotelCode);
        memberLoginParamDto.setL2RMemberNo(l2RMemberNo);
        memberLoginParamDto.setCurrentPage(currentPage);
        memberLoginParamDto.setPageSize(pageSize);
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(HandlerUtil.pmsMemberHandler().getPmsMemberCouponsHandler(memberLoginParamDto));
        return l2rRs;
    }

    @RequestMapping(value = "/GetCardBalanceInfo", method = RequestMethod.GET)
    public BaseResultDto getCardBalanceInfo(
            @RequestParam(value = "l2RMemberNo", required = false) String l2RMemberNo
    ) throws Exception {
        MemberLoginInsideParamDto memberLoginInsideParamDto =new MemberLoginInsideParamDto();
        memberLoginInsideParamDto.setL2RMemberNo(l2RMemberNo);
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo( HandlerUtil.pmsMemberHandler().getCardBalanceInfoHandler(memberLoginInsideParamDto ));
        return l2rRs;
    }

    @RequestMapping(value = "/UsePoint", method = RequestMethod.POST)
    public BaseResultDto usePoint(
            @RequestBody PointPresentUseInsideParamDto pointPresentUseInsideParamDto
    ) throws Exception {
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultCode(0);
        HandlerUtil.pmsMemberHandler().usePointHandler(pointPresentUseInsideParamDto);
        return l2rRs;
    }

    @RequestMapping(value = "/AddPoint", method = RequestMethod.POST)
    public BaseResultDto addPoint(
            @RequestBody PointPresentUseInsideParamDto pointPresentUseInsideParamDto
    ) throws Exception {
        BaseResultDto baseResultDto = new BaseResultDto();
        baseResultDto.setResultCode(0);
        HandlerUtil.pmsMemberHandler().presentPointHandler(pointPresentUseInsideParamDto);
        return baseResultDto;
    }

    @RequestMapping(value = "/SaleCoupons", method = RequestMethod.POST)
    public BaseResultDto saleCoupons(
            @RequestBody UsableCouopnsInsideParamDto usableCouopnsInsideParamDto
    ) throws Exception {
        BaseResultDto baseResultDto = new BaseResultDto();
        baseResultDto.setResultCode(0);
        HandlerUtil.pmsMemberHandler().onlineSaleCouponHandler(usableCouopnsInsideParamDto);
        return baseResultDto;
    }

    @RequestMapping(value = "/SaleCouponsNew", method = RequestMethod.POST)
    public BaseResultDto saleCouponsNew(
            @RequestBody UsableCouopnsInsideParamDto usableCouopnsInsideParamDto
    ) throws Exception {
        BaseResultDto baseResultDto = new BaseResultDto();
        baseResultDto.setResultCode(0);
        HandlerUtil.pmsMemberHandler().onlineSaleCouponNewHandler(usableCouopnsInsideParamDto);
        return baseResultDto;
    }

    @RequestMapping(value = "/UpgradeMmeber", method = RequestMethod.PUT)
    public BaseResultDto upgradeMmeber(
            @RequestBody MemberUpgradeInsideParamDto memberUpgradeInsideParamDto
    ) throws Exception {
        BaseResultDto baseResultDto = new BaseResultDto();
        baseResultDto.setResultCode(0);
        baseResultDto.setResultInfo(HandlerUtil.pmsMemberHandler().upgradePmsMemberLevelHandler(memberUpgradeInsideParamDto));
        return baseResultDto;
    }

    @RequestMapping(value = "/ExchangePackage", method = RequestMethod.POST)
    public BaseResultDto upgradeMmeber(
            @RequestBody MemberPackageInsideParamDto memberPackageInsideParamDto
    ) throws Exception {
        HandlerUtil.pmsMemberHandler().exchangePackageHandler(memberPackageInsideParamDto);
        BaseResultDto baseResultDto = new BaseResultDto();
        baseResultDto.setResultCode(0);
        return baseResultDto;
    }
    
    @RequestMapping(value = "/CoupenCodeCollarCoupen", method = RequestMethod.POST)
    public BaseResultDto coupenCodeCollarCoupen(
            @RequestBody MemberCoupenCodeCollarCoupenInsideParamDto memberCouponsCodeInsideParamDto
    ) throws Exception {
        HandlerUtil.pmsMemberHandler().coupenCodeCollarCoupenHandler(memberCouponsCodeInsideParamDto);
        BaseResultDto baseResultDto = new BaseResultDto();
        baseResultDto.setResultCode(0);
        return baseResultDto;
    }
}


